// @title           好租
// @version         1.0
// @description     租房找好租
// @host            localhost:8080
// @BasePath        /

package main

import (
	"flag"
	"strconv"

	"github.com/gin-gonic/gin"
	"good.house/config"
	"good.house/internal/database"
	"good.house/internal/log"
	"good.house/internal/router"
	"good.house/internal/validator"
)

// 启动命令 go run main.go -env=development
func main() {
	env := flag.String("env", "development", "运行环境 (development/test/production)")
	flag.Parse()

	cfg := config.Load(*env)

	log.SetupLog(cfg)

	db := database.InitDB(cfg)
	rdb := database.InitRedis(cfg)

	gin.SetMode(cfg.Server.Mode)

	validator.RegisterCustomValidators()

	r := router.SetupRouter(db, rdb, cfg)

	r.Run(":" + strconv.Itoa(cfg.Server.Port))
}
